package com.intelligent.ispc.core.entity;

import com.google.common.collect.Lists;
import com.intelligent.ispc.common.persistence.BaseEntity;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import java.util.List;

/**
 * Created by Can.Guan on 2016/5/3.
 */
@Entity
@Table(name = "t_group")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Group extends BaseEntity{
    private String name;
    private String description;

    @ManyToMany(
            targetEntity = User.class,
            cascade = {CascadeType.PERSIST, CascadeType.MERGE},
            mappedBy = "groups"
    )
    private List<User> users = Lists.newArrayList();

    @ManyToMany(
            targetEntity = Project.class,
            cascade = {CascadeType.PERSIST, CascadeType.MERGE},
            mappedBy = "groups"
    )
    private List<Project> projects = Lists.newArrayList();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public List<Project> getProjects() {
        return projects;
    }

    public void setProjects(List<Project> projects) {
        this.projects = projects;
    }
}
